package cn.kgc.controller;

import cn.kgc.dto.AddSysUserDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Email;
import javax.validation.constraints.Max;
import javax.validation.constraints.NotBlank;


/**
 * <p>添加描述信息</p>
 *
 * @author 石浩杰
 * @since 2022年09月26日 8:35
 */
@RestController
@Api(tags = "JSR303示例")
@RequestMapping("/jsr303")
@Validated
public class JSR303Controller {

    @PostMapping("/add")
    @CrossOrigin
    @ApiOperation(value = "新增用户使用JSR303服务器端验证，验证新增用户是否符合规则")
    public boolean add(@Validated@RequestBody AddSysUserDTO addSysUserDTO){
        return true;
    }

    @GetMapping("/{id}")
    @CrossOrigin
    @ApiOperation(value = "使用JSR303服务器端验证,rest风格传递参数")
    @ApiImplicitParam(name = "id",value = "id的值",paramType = "path")
    public AddSysUserDTO get(@Max(value = 3,message = "id最大值3")@PathVariable("id")int id){
        return new AddSysUserDTO();
    }

    @PutMapping("/update")
    @CrossOrigin
    @ApiOperation(value = "传递多个参数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",value = "用户名",paramType = "query"),
            @ApiImplicitParam(name = "email",value = "邮箱",paramType = "query"),
    })
    public boolean update(@NotBlank(message = "名字不能为空")@RequestParam String name,
                          @NotBlank(message = "邮箱不能为空") @Email(message = "邮箱格式不正确") String email){
        return true;
    }
}
